import request from '@/utils/request'

const api = {
  findUserByPage: '/user/findUserByPage',
  addUser: '/user/addUser',
  deleteUserById: '/user/deleteUserById',
  updateUser: '/user/updateUser',
  uploadAvatar: '/user/uploadAvatar',
  changePassword: '/user/changePassword',
  assignUserRoles: '/user/assignUserRoles',
  findUserById: '/user/findUserById',
  downloadAvatar: '/user/downloadAvatar/',
  findAllUserByPermissionCode: '/user/findAllUserByPermissionCode'
}

export default api

export function findUserByPage(parameter) {
  return request({
    url: api.findUserByPage,
    method: 'get',
    params: parameter
  })
}

export function changePassword(parameter) {
  return request({
    url: api.changePassword,
    method: 'post',
    data: parameter
  })
}

export function addUser(parameter) {
  return request({
    url: api.addUser,
    method: 'post',
    data: parameter
  })
}

export function deleteUserById(parameter) {
  return request({
    url: api.deleteUserById,
    method: 'post',
    params: parameter
  })
}

export function updateUser(parameter) {
  return request({
    url: api.updateUser,
    method: 'post',
    data: parameter
  })
}

export function assignUserRoles(parameter) {
  return request({
    url: api.assignUserRoles,
    method: 'post',
    data: parameter
  })
}


export function findUserById(parameter) {
  return request({
    url: api.findUserById,
    method: 'get',
    params: parameter
  })
}

export function findAllUserByPermissionCode(parameter) {
  return request({
    url: api.findAllUserByPermissionCode,
    method: 'get',
    params: parameter
  })
}

/**
 * 下载头像
 * @param parameter
 * @returns {string}
 */
export function downloadAvatar(parameter) {
  return api.downloadAvatar + parameter.fileName
}
